import java.util.HashMap;
import java.util.Map;

// https://leetcode.cn/problems/decode-the-message/
public class Solution {
    public static String decodeMessage(String key, String message) {
        Map<Character, Character> map = new HashMap<>();
        StringBuilder stringBuilder = new StringBuilder();
        char count = 'a';
        map.put(' ', ' ');
        for (int i = 0; i < key.length(); i++) {
            if (!map.containsKey(key.charAt(i))) {
                map.put(key.charAt(i), count);
                count++;
            }
        }
        for (int i = 0; i < message.length(); i++) {
            stringBuilder.append(map.get(message.charAt(i)));
        }
        return stringBuilder.toString();
    }

    public static void main(String[] args) {
        String key = "eljuxhpwnyrdgtqkviszcfmabo";
        String message = "zwx hnfx lqantp mnoeius ycgk vcnjrdb";

        System.out.println(decodeMessage(key, message));
    }
}
